package com.itcaius.myandroidhomework;

import android.app.Application;

import androidx.room.Room;

import com.itcaius.myandroidhomework.data.database.UserDatabase;
import com.itcaius.myandroidhomework.data.repo.UserRepository;

public class MyApplication extends Application {

    private static UserDatabase userDatabase;
    private static UserRepository userRepo;

    @Override
    public void onCreate() {
        super.onCreate();
        //初始化数据库
        userDatabase = Room.databaseBuilder(getApplicationContext(),
                UserDatabase.class, "user-database").build();
        userRepo = new UserRepository(userDatabase.userDao());
    }

    public static UserRepository getUserRepo(){
        return userRepo;
    }
}
